<?php

namespace app\model\office;

use app\model\BaseModel;
use app\model\exam\ExamSend;
use think\model\concern\SoftDelete;

class OfficeClass extends BaseModel
{
    use SoftDelete;

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $table = 'free_office_class';
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';

    protected $type = [
        'is_drat' => 'boolean',
        'is_speed' => 'boolean',
    ];


    public function majors()
    {
        return $this->hasOne(OfficeMajor::class, 'id', 'major_id');
    }


    public function searchTitleAttr($query, $value)
    {
        $query->where('title', 'like', '%' . $value . '%');
    }

    /**
     * 年级搜索器
     * @param $query
     * @param $value
     * @return void
     */
    public function searchGardeAttr($query, $value)
    {
        $query->where('garde', 'like', '%' . $value . '%');
    }

    /**
     * 课程类别搜索器
     * @param $query
     * @param $value
     * @return void
     */
    public function searchClassTypeAttr($query, $value)
    {
        $query->where('class_type', 'like', '%' . $value . '%');
    }

    /**
     * 专业类别搜索器
     * @param $query
     * @param $value
     * @return void
     */
    public function searchMajorIdAttr($query, $value)
    {
        if ($value) $query->where('major_id', $value);
    }

    /**
     * 课程代码搜索器
     * @param $query
     * @param $value
     * @return void
     */
    public function searchClassCodeAttr($query, $value)
    {
        $query->where('class_code', 'like', '%' . $value . '%');

    }


    //-----------------------------------------------api-----------------------------------------------------
    public function test(){
        return $this->hasMany(ExamSend::class,'class_id','id');
    }
}